package com.example.kafka.consumer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class Consumer {

    @KafkaListener(topics = "test")
    public void listen(ConsumerRecord<? , ?> record) {
        Optional<?> kafkaMessage = Optional.ofNullable(record.value());
        // 对象存在
        if (kafkaMessage.isPresent()) {
            Object message = kafkaMessage.get();
            System.out.println("========消费者消费=========");
            System.out.println("message = " + message);
            System.out.println("record = " + record);
            System.out.println("record.offset() = " + record.offset());
            System.out.println("record.partition() = " + record.partition());
            System.out.println("========消费者消费=========");
        }
    }

}